package com.it.zhangjun.arithmetic.链表;

/**
 * @author zhangj
 * @description 环形链表
 * @date 2021-03-17 20:05
 */
public class LT_141 {

    public static boolean hasCycle(ListNode head) {
        if (head == null || head.next == null) {
            return false;
        }
        ListNode slow = head;
        ListNode fast = head.next;
        while (fast != null && fast.next != null) {
            if (slow == fast) {
                return true;
            }
            slow = slow.next;
            fast = fast.next.next;
        }
        return false;
    }
}